package io.renren.common.utils;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class ExcelDateUtil {
    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Date getDate(int days) {
        Calendar c = Calendar.getInstance();
        c.set(1900, 0, 1);
        c.add(Calendar.DATE, days - 2);
        return c.getTime();
    }

    public static Date getTime(Date date, double ditNumber) {
        Calendar c = Calendar.getInstance();
        int mills = (int) (Math.round(ditNumber * 24 * 3600));
        int hour = mills / 3600;
        int minute = (mills - hour * 3600) / 60;
        int second = mills - hour * 3600 - minute * 60;
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, hour);
        c.set(Calendar.MINUTE, minute);
        c.set(Calendar.SECOND, second);
        return c.getTime();
    }

    public static Date getDate(String day, String time) {
        int days = Integer.valueOf(day);
        Double ditNumber = Double.valueOf(time);
        Date date = getDate(days);
        return getTime(date, ditNumber);
    }
}
